<?php
namespace app\middleware;

use app\model\ManageLogModel;
use Webman\MiddlewareInterface;
use Webman\Http\Response;
use Webman\Http\Request;

class ManageMain implements MiddlewareInterface
{
    public function process(Request $request, callable $handler) : Response
    {
        // $session = $request->session();
        // $uid = $session->get('uid', '');
		
		$uid=session('uid','');
		if($request->controller=="app\manage\controller\LoginController"){ //这个是微信支付的回调，以后回调都写在这个控制器里面的了
		
		}else{
		    if(!$uid){
		        return redirect('/manage');
		    }
		}
		if($uid){
		    //记录日志
		    ManageLogModel::create([
		        'uid'=>$uid,
		        'url'=>$request->uri(),
		        'ip'=>$request->getRealIp($safe_mode=true),
		        'parame'=>json_encode($request->all()),
		    ]);
		}
		

        $response = $handler($request); // 继续向洋葱芯穿越，直至执行控制器得到响应
		
		
		
		
		
        return $response;
    }
}